<?php

error_reporting(E_ALL);

$http_errors = array(
  400 =>  "400 Bad Request",
  404 =>  "404 Not Found",
  500 =>  "500 Internal Server Error");

ob_start();

try {

	include 'include/db.php';
	include 'include/functions.php';
	
	if (!isset($_SERVER["REDIRECT_URL"]) || $_SERVER["REDIRECT_URL"] == "/") {
	
	    include "content/home.php";
	    
	} else {
	    
	    $content_file = "content/" .
	                    substr($_SERVER["REDIRECT_URL"], 1, strlen($_SERVER["REDIRECT_URL"]) - 1) .
	                    ".php";
	    
	    if (file_exists($content_file)) {
	        include $content_file;
	    } else {
			throw new Exception("The requested URL ". $_SERVER["REQUEST_URI"] ." was not found.", 404);
	    }
	}
} catch (Exception $e) {

	ob_end_clean();
	header("HTTP/1.1 ". $http_errors[$e->getCode()]);
	ob_start();
	include "content/error.php";
}

$output = ob_get_contents();
ob_end_clean();

?><!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Canoodle</title>
    <meta name="description" content="">
    <meta name="author" content="">
    
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    
    <link href="/assets/css/bootstrap.css" rel="stylesheet">
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="/assets/css/bootstrap-responsive.css" rel="stylesheet">
    <link href="/assets/css/canoodle.css" rel="stylesheet">

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="/assets/js/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="/assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/assets/js/jquery.sparkline.js"></script>
    <script type="text/javascript" src="/assets/js/canoodle.js"></script>
  </head>
  <body>
    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="/">Canoodle</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li><a href="/">Home</a></li>
              <li><a href="/about">About</a></li>
            </ul>
          </div>
          <form class="navbar-search pull-right" action="/search">
            <input name="term" type="text" class="search-query" placeholder="Search">
          </form>
        </div>
      </div>
    </div>
    <div class="container">
<?php echo $output; ?>
      <hr>
      <footer>
        <p>&copy; 2012
          Josh Blevins <i class="icon-star"></i>
          James Corcoran <i class="icon-star"></i>
          Jason Eisenmenger</p>
        <p>
          <a href="http://code.google.com/p/uofl-cecs-550-spring-2012/">Google Project Home</a>
          |
          <a href="/phpmyadmin">phpMyAdmin</a>
          |
          <a href="/phpsysinfo">System Stats</a>
          |
          <a href="/phpinfo">phpinfo</a>
      </footer>
    </div> <!-- /container -->
  </body>
</html>